package mancala.ui;

import static mancala.Mancala.getImageIcon;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.Icon;
import javax.swing.SwingConstants;

import mancala.model.Player;

public class PlayerImpl extends Player {
    private static final long serialVersionUID = 1L;
    private final Dimension minSize = new Dimension(550, 80);

    public PlayerImpl(int id, String name) {
        setId(id);
        setName(name);

        setText(name);
        setBackground(Color.YELLOW);
        setFont(new Font("Arial", Font.BOLD, 32));
        setHorizontalAlignment(getId() == 1 ? LEFT : RIGHT);
        setVerticalAlignment(id == 2 ? SwingConstants.BOTTOM : SwingConstants.TOP);
        setVerticalTextPosition(id == 2 ? SwingConstants.BOTTOM : SwingConstants.TOP);
        setHorizontalTextPosition(SwingConstants.CENTER);
        setOpaque(false);
        setForeground(Color.WHITE);
        int y = id == 1 ? 395 : 10;
        setLocation(130, y);
        setSize(minSize);
    }

    @Override
    public Icon getIcon() {
        boolean active = isActive();
        return active ? getImageIcon("current.png") : null;
    }
}